/*
编译：gcc power.c -o power -L lib -l wiringPi (需已安装wiringPi)
安装：编辑文件/etc/rc.local，添加"/path-to-here/power &"到文件的"exit 0"之前
by：WuSiYu
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <wiringPi.h>
#include <iconv.h> 

#define PORT 7

int main(){
	wiringPiSetup();
	pinMode(PORT, INPUT);
	while(1){
		sleep(10);
		// check
		if(!digitalRead(PORT)){
			// poweroff
			system("sudo poweroff");
		}
	}
	return 0;
}